package com.ufox.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ufox.entity.Products;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ufox.req.ProductsCondREQ;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 优狐科技-www.hbufox.com
 * @since 2022-06-09
 */
public interface ProductsMapper extends BaseMapper<Products> {

    @Select("SELECT *,(SELECT NAME from `type` WHERE id = typeid) `typename` FROM products WHERE id =#{id}")
    int findProdById(@Param("id") String id);

    Page<Products> selectAllByCond(Page<Products> pageInfo,@Param("cond") ProductsCondREQ productsCond);


    @Update("update products set pnum = pnum-#{pnum} where id = #{id}")
    int updateProdNumByIdjian(@Param("pnum") String pnum,@Param("id") String id);

//    @Update("update products set pnum = pnum + #{num} where id = #{id}")
//    int updateProdNumByIdjia(@Param("num") String num,@Param("id") String id);

    Page<Products> findProdByUser(@Param("id") String id, Page<Products> pageInfo,@Param("cond") ProductsCondREQ productsCond);

    @Update("update products set state = #{state} where id = #{id}")
    int updateProdStateById(@Param("state") String state,@Param("id") String id);

    Products findById(@Param("prodId")String prodId,@Param("userId")String userId);

    Products selectProdAndUser(@Param("prodId") Integer prodId);

    void updateProdById(Products products);

    IPage<Products> selectByTypeIdPage(IPage<Products> pageInfo,@Param("typeid") String typeid);

    Products selectDetailById(String id);

    IPage<Products> selectProductsByName(IPage<Products> pageInfo,@Param("name")  String name);

}
